<template>
	
	
	<div>
		<div style="font-size: 0.9rem;border-bottom: solid 1px #9D9E9E;" v-for="(item,index) in list">
		
			<div class="flex" style="padding: 0.5rem;">
				
				<div style=" flex-direction:column;width: 75%;">
					
					<div class="flex">
						
						<div style="flex-direction:column;">
							<img :src="item.share_avatar_url" style="width: 3rem;height: 3rem;border-radius: 50%;"/>
						</div>
						<div style="flex-direction:column;line-height: 3rem;margin-left: 0.6rem;">
							<div>{{item.share_nickname}}</div>
						</div>
						<div style="flex-direction:column;line-height: 3rem;margin-left: 0.6rem;">
							<div>分享:{{item.share_num}}张</div>
						</div>
						<div style="flex-direction:column;line-height: 3rem;margin-left: 0.6rem;">
							<div>剩余:{{item.left_num}}张</div>
						</div>
						
					</div>
					
					<div>
						转赠时间：{{item.addtime}}
					</div>
					
				</div>
				<div style=" flex-direction:column">
					<div v-if="item.status == 2" style="width: 4rem;text-align: center;background: #C6000B;color: #FFFFFF;border-radius: 0.2rem;margin-top: 0.5rem;">已被领取</div>
					<div v-if="item.status == 3" style="width: 4rem;text-align: center;background: #C6000B;color: #FFFFFF;border-radius: 0.2rem;margin-top: 0.5rem;">已失效</div>
					<div v-if="item.status == 1 || item.status == 0" @click="continueDo(index)" style="width: 4rem;text-align: center;background: #65037A;color: #FFFFFF;border-radius: 0.2rem;margin-top: 0.5rem;">继续转赠</div>
					<div @click="cancelDo(index)" style="width: 4rem;text-align: center;background: #888888;color: #FFFFFF;border-radius: 0.2rem;margin-top: 0.9rem;">取消转赠</div>
					
				</div>
				
			</div>
			
			
		</div>
		
		<div v-if="list.length == 0" style="text-align: center;margin-top: 1rem;">暂无转赠记录！</div>
		
	</div>
	
	
	
	
</template>

<script>
	import { base64} from 'vux'
	export default {
		components: {         
            base64
		},
		data(){
			
			return{
				
				access_token:'',
				list:''
				
			}
			
		},
		
		methods:{
			
			//获取详情
		    getDetail(){
		    	
		    	this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.get(this.$store.state.api + 'index/level-log&access_token=' + this.access_token)
		    	.then((response) => {
		    		
		    		console.log(response)
		    		
				
				if(response.body.code == 0) {
					
					this.list = response.body.data
					
				} else {
					
					this.list = ''
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
				
				
			    }, (response) => {
	             
	             
			    });
		    },
		    
		    //继续转赠
		    continueDo(res){
		    	
		    	console.log(res)
		    	
		    	var id = this.list[res].id
		    	
		    	this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.get(this.$store.state.api + 'index/continue-share&access_token=' + this.access_token +'&id=' + id)
		    	.then((response) => {
		    		
		    		console.log(response)
		    		
				
				if(response.body.code == 0) {
					
					
					
				} else {
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
				
				
			    }, (response) => {
	             
	             
			    });
		    	
		    },
			
			//取消转赠
			cancelDo(res){
				
				var id = this.list[res].id
				
				this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.get(this.$store.state.api + 'index/cancel-share&access_token=' + this.access_token +'&id=' + id)
		    	.then((response) => {
		    		
		    		console.log(response)
		    		
				
				if(response.body.code == 0) {
					
					this.getDetail()
					
				} else {
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
				
				
			    }, (response) => {
	             
	             
			    });
				
			},
			
			//获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },	
			
			
		},
		
		mounted(){
			
			var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
           
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
    	   this.access_token = localStorage.getItem('access_token');
			
			this.getDetail();
			
		}
		
		
	}
	
</script>

<style>
</style>